package top.anydata.lifeofcode.lifesystem.service.sys.user.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import top.anydata.lifeofcode.lifesystem.dao.sys.user.ISysAuthUserRepository;
import top.anydata.lifeofcode.lifesystem.service.sys.user.IUserService;

/**
 * 功能描述:
 *
 * @author <a href="mailto:caingao@anydata.top">CainGao</a>
 * @version V_1.0
 * @date 2023/9/6 3:58 PM
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class UserDetailsServiceImpl implements IUserService {

    private final ISysAuthUserRepository sysAuthUserDao;
    @Override
    public UserDetailsService userDetailsService() {
        return new UserDetailsService() {
            @Override
            public UserDetails loadUserByUsername(String username) {
                log.info("用户登录:{}",username);
                return sysAuthUserDao.findByEmail(username)
                        .orElseThrow(() -> new UsernameNotFoundException("User not found"));
            }
        };
    }
}
